# -*- coding:utf-8 -*-

"""
    Copyright 2010 Yurtaev Egor

    This file is part of webapp-dcpp-log.

    webapp-dcpp-log is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    webapp-dcpp-log is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with webapp-dcpp-log. If not, see http://www.gnu.org/licenses/.
"""

import web
from Lib.makeJSON import makeJSON

urls = ('/', 'index',
        '/json/(.*)/', 'GetMsg',
        '/userlist/','GetUserlist',
        '/IDLastMsg/','GetIDLastMsg')

db = web.database(dbn="sqlite", db="LogBot/dbChat.sqlite")

render = web.template.render('templates/', cache=True)
app = web.application(urls, globals())

getJSON = makeJSON(db)

class GetMsg:
    def GET(self, id):
        web.header('Content-Type', 'text/javascript; charset=utf-8')
        return getJSON.msg(id)

class GetUserlist:
    def GET(self):
        web.header('Content-Type', 'text/javascript; charset=utf-8')
        return getJSON.userlist()

class GetIDLastMsg:
    def GET(self):
        web.header('Content-Type', 'text/javascript; charset=utf-8')
        return getJSON.idLastMsg()

class index:
    def GET(self):
        web.header("Content-Type","text/html; charset=utf-8")
        return render.main_log()


if __name__ == "__main__": app.run()